package com.ruoyi.web.controller.bkcontroller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Income;
import com.ruoyi.system.service.IIncomeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 收入Controller
 * 
 * @author ruoyi
 * @date 2021-08-10
 */
@RestController
@RequestMapping("/system/income")
public class IncomeController extends BaseController
{
    @Autowired
    private IIncomeService incomeService;

    /**
     * 查询收入列表
     */
    @PreAuthorize("@ss.hasPermi('system:income:list')")
    @GetMapping("/list")
    public TableDataInfo list(Income income)
    {
        startPage();
        List<Income> list = incomeService.selectIncomeList(income);
        return getDataTable(list);
    }

    /**
     * 导出收入列表
     */
    @PreAuthorize("@ss.hasPermi('system:income:export')")
    @Log(title = "收入", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Income income)
    {
        List<Income> list = incomeService.selectIncomeList(income);
        ExcelUtil<Income> util = new ExcelUtil<Income>(Income.class);
        return util.exportExcel(list, "收入数据");
    }

    /**
     * 获取收入详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:income:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(incomeService.selectIncomeById(id));
    }

    /**
     * 新增收入
     */
    @PreAuthorize("@ss.hasPermi('system:income:add')")
    @Log(title = "收入", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Income income)
    {
        income.setCreateBy(getUsername());
        return toAjax(incomeService.insertIncome(income));
    }

    /**
     * 修改收入
     */
    @PreAuthorize("@ss.hasPermi('system:income:edit')")
    @Log(title = "收入", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Income income)
    {
        income.setUpdateBy(getUsername());
        return toAjax(incomeService.updateIncome(income));
    }

    /**
     * 删除收入
     */
    @PreAuthorize("@ss.hasPermi('system:income:remove')")
    @Log(title = "收入", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(incomeService.deleteIncomeByIds(ids));
    }
}
